/*
 *
 *  *   Copyright (c) 2018  xuefeng.gao All rights reserved.
 *  *   @Author:高雪峰
 *  *   @Mail:ourjava@foxmail.com
 *  *   @LastModified:2018
 *
 *
 */

package com.icesoft.xsnow.oauth.constants;

import com.icesoft.xsnow.common.core.constant.SecurityConstants;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * 需要放开权限的url
 *
 * @author 小威老师
 */
public final class PermitAllUrl {

    /**
     * 监控中心和swagger需要访问的url
     */
    private static final String[] ENDPOINTS = {"" +
            "/favicon.ico",
            "/actuator/**",
            "/global/**",
            "/oauth/removeToken",
            "/oauth/delToken/*",
            "/oauth/listToken",
            "/oauth/failure",
            "/oauth/token/*",
            SecurityConstants.LOGIN_PAGE,
            SecurityConstants.LOGIN_PROCESS_URL,
            SecurityConstants.OAUTH_APPROVAL_CONFIRM_URL,
            "/code/**",
            "/login",
            "/login?error",
            "/logout",
            "/mobile/**",
            "/v2/api-docs/**",
            "/swagger-ui.html",
            "/swagger-resources/**",
            "/index.html",
            "/webjars/**",
            "/static/**",
            "/assets/**",
            "/**/*.png",
            "/**/*.jpg",
            "/views/**"
    };

    /**
     * 需要放开权限的url
     *
     * @param urls 自定义的url
     * @return 自定义的url和监控中心需要访问的url集合
     */
    public static String[] permitAllUrl(String... urls) {
        if (urls == null || urls.length == 0) {
            return ENDPOINTS;
        }

        Set<String> set = new HashSet<>();
        Collections.addAll(set, ENDPOINTS);
        Collections.addAll(set, urls);

        return set.toArray(new String[set.size()]);
    }

}
